//
//  SampleBookMainView.m
//  Zinipad
//
//  Created by ZeLkOvA on 12. 5. 17..
//  Copyright (c) 2012년 __MyCompanyName__. All rights reserved.
//

#import "SampleBookColorViewWallpaper.h"
#import "iCarouselColor.h"

//#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

//#define NUMBER_OF_ITEMS 6
#define NUMBER_OF_VISIBLE_ITEMS 7
#define ITEM_SPACING 50.0f
#define INCLUDE_PLACEHOLDERS YES

@interface SampleBookColorViewWallpaper() <UIActionSheetDelegate>

@property (nonatomic, assign) BOOL wrap;
@property (nonatomic, retain) NSMutableArray *items;

@end

@implementation SampleBookColorViewWallpaper

@synthesize carousel;
@synthesize wrap;
@synthesize items;

//@synthesize carouselColor;

- (void)setUpImg
{
    //set up data
    wrap = YES;
    self.items = [NSMutableArray array];
    //     imgArray = [[NSMutableArray alloc] init];
    
    // 이미지 가져와서 저장하기 
    [items addObject:@"a.png"];
    [items addObject:@"b.png"];
    [items addObject:@"c.png"];
    [items addObject:@"a.png"];
    [items addObject:@"b.png"];
    [items addObject:@"c.png"];
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [self setUpImg];
        
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
 // Implement loadView to create a view hierarchy programmatically, without using a nib.
 - (void)loadView
 {
 }
 */

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self InitColorCarousel]; 
}

-(void)InitColorCarousel
{
    carouselColor = [[iCarouselColor alloc] init];
    [carouselColor setFrame:CGRectMake(0,0,150,300)];
    carouselColor.dataSourceColor = self;
    carouselColor.delegate = self;
    [self.view addSubview:carouselColor];
//    carouselColor.delegate = self;
//    carouselColor.dataSourceColor = self;
    carouselColor.type = iCarouselColorTypeWheel;
    carouselColor.vertical = !carouselColor.vertical;
}

- (void)carouselCurrnetImgIndexColor:(int)_imgIndex;
{
    NSLog(@"ImgIndexColor    awfafawfawfawfawdawfawfqga    == %d",_imgIndex);
    //    UIImage* tileBGImage = [UIImage imageNamed:[items objectAtIndex:_imgIndex]];
    //    [detailImageView setImage:tileBGImage];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (NSUInteger)numberOfItemsInCarouselColor:(iCarouselColor *)carousel
{
    return [items count];
}

- (NSUInteger)numberOfVisibleItemsInCarouselColor:(iCarouselColor *)carousel
{
    //limit the number of items views loaded concurrently (for performance reasons)
    //this also affects the appearance of circular-type carousels
    return NUMBER_OF_VISIBLE_ITEMS;
}

- (UIView *)carouselColor:(iCarouselColor *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
    if (view == nil)
    {
        NSLog(@"here %d",index);
        view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:[items objectAtIndex:index]]] autorelease];
        [view setFrame:CGRectMake(0, 0, 80, 50)];
        view.layer.doubleSided = YES; //prevent back side of view from showing
        
        //        label = [[[UILabel alloc] initWithFrame:view.bounds] autorelease];
        //        label.backgroundColor = [UIColor clearColor];
        //        label.textAlignment = UITextAlignmentCenter;
        //        label.font = [label.font fontWithSize:10];
        //        label.text =  [NSString stringWithFormat:@"%d",count];
        //        [view addSubview:label];
        //        count++;
    }
    else
    {
        NSLog(@"here %d",index);
        view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:[items objectAtIndex:index]]] autorelease];
        [view setFrame:CGRectMake(0, 0, 80, 50)];
        view.layer.doubleSided = YES; 
        
    }
    //   
    return view;
}

- (NSUInteger)numberOfPlaceholdersInCarouselColor:(iCarouselColor *)carousel
{
    //note: placeholder views are only displayed on some carousels if wrapping is disabled
    return 0;
}


- (CGFloat)carouselItemWidthColor:(iCarouselColor *)carousel
{
    //usually this should be slightly wider than the item views
    return ITEM_SPACING;
}

- (BOOL)carouselShouldWrapColor:(iCarouselColor *)carousel
{
    return wrap;
}

-(void)dealloc
{
    carouselColor.delegate = nil;
    carouselColor.dataSourceColor = nil;
    [carouselColor release];
    [items release];
    [super dealloc];
}

#pragma mark - Button Handler


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
	return YES;
}

@end

